/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package info.jaguaribe.jaguaribe;

import info.jaguaribe.common.KeyboardUtils;

/**
 *
 * @author fernando
 */
@SuppressWarnings("serial")
public class KeyboardPressDialog extends javax.swing.JDialog {
    /**
     * If the user close the window using the ok button, status is true,
     * otherwise is false
     */
    public Boolean status = false;

    /**
     * Creates new form KeyboardPressDialog
     *
     * @param parent
     * @param modal
     */
    public KeyboardPressDialog(PreferencesFrame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.textShortcut.setEditable(false);
    }

    /**
     *
     * @return
     */
    public String getKeystroke() {
        return (this.textShortcut.getText());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelDescription = new javax.swing.JLabel();
        textShortcut = new javax.swing.JTextField();
        buttonClear = new javax.swing.JButton();
        buttonOk = new javax.swing.JButton();
        buttonCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("info/jaguaribe/jaguaribe/Bundle"); // NOI18N
        labelDescription.setText(bundle.getString("KeyboardPressDialog.labelDescription.text")); // NOI18N

        textShortcut.setText(bundle.getString("KeyboardPressDialog.textShortcut.text")); // NOI18N
        textShortcut.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                textShortcutKeyPressed(evt);
            }
        });

        buttonClear.setText(bundle.getString("KeyboardPressDialog.buttonClear.text")); // NOI18N
        buttonClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonClearActionPerformed(evt);
            }
        });

        buttonOk.setText(bundle.getString("KeyboardPressDialog.buttonOk.text")); // NOI18N
        buttonOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonOkActionPerformed(evt);
            }
        });

        buttonCancel.setText(bundle.getString("KeyboardPressDialog.buttonCancel.text")); // NOI18N
        buttonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(labelDescription, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(textShortcut)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(buttonClear, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addComponent(buttonOk, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonCancel, buttonClear, buttonOk});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(labelDescription, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(textShortcut, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonClear)
                    .addComponent(buttonOk)
                    .addComponent(buttonCancel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Event. When the button clear is clicked.
     *
     * @param evt The event.
     */
    private void buttonClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonClearActionPerformed
        this.textShortcut.setText("");
    }//GEN-LAST:event_buttonClearActionPerformed

    /**
     * Event. When a key is pressed in the textbox shortcut.
     *
     * @param evt The event.
     */
    private void textShortcutKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textShortcutKeyPressed
        this.textShortcut.setText(KeyboardUtils.keyEvent2keyStroke(evt));
    }//GEN-LAST:event_textShortcutKeyPressed

    /**
     * Event. When the button cancel is clicked.
     *
     * @param evt The event.
     */
    private void buttonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelActionPerformed
        this.dispose();
    }//GEN-LAST:event_buttonCancelActionPerformed

    /**
     * Event. When the button ok is clicked.
     *
     * @param evt The event.
     */
    private void buttonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonOkActionPerformed
        this.status = true;
        this.dispose();
    }//GEN-LAST:event_buttonOkActionPerformed
    //@cond
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonCancel;
    private javax.swing.JButton buttonClear;
    private javax.swing.JButton buttonOk;
    private javax.swing.JLabel labelDescription;
    private javax.swing.JTextField textShortcut;
    // End of variables declaration//GEN-END:variables
    //@endcond
}
